package cn.adolf.carmaster.helper;

import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;

import cn.adolf.carmaster.App;

/**
 * @program: CarMaster
 * @description: 不用担心线程的toast
 * @author: 豚豚
 * @create: 2021-12-06 08:50
 **/
public class ToastUtil {
    private static Handler mHandler;

    public static void show(String msg) {
        if (mHandler == null) {
            mHandler = new Handler(Looper.getMainLooper());
        }

        mHandler.post(() -> Toast.makeText(App.getContext(), msg, Toast.LENGTH_SHORT).show());
    }

    public static void show(String msg, long delay) {
        if (mHandler == null) {
            mHandler = new Handler(Looper.getMainLooper());
        }

        mHandler.postDelayed(() -> Toast.makeText(App.getContext(), msg, Toast.LENGTH_SHORT).show(), delay);
    }
}
